package com.bjsxt.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bjsxt.domain.Notice;
import com.bjsxt.mapper.NoticeMapper;
import com.bjsxt.service.NoticeService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> implements NoticeService {

    /**
     * 分页查询公告数据
     *
     * @param page      分页对象<Notice>
     * @param title     标题
     * @param startTime 开始时间
     * @param endTime   结束时间
     * @param status    状态
     * @return 公告分页数据对象
     */
    @Override
    public Page<Notice> pageByTitleAndCreateTimeAndStatus(Page<Notice> page, String title, Date startTime, Date endTime, Integer status) {
        // 调用分页方法进行分页数据的查询
        return page(page, new LambdaQueryWrapper<Notice>()
                .like(StringUtils.isNotBlank(title), Notice::getTitle, title)
                .ge(startTime != null, Notice::getCreated, startTime)
                .le(endTime != null, Notice::getCreated, endTime)
                .eq(status != null, Notice::getStatus, status)
        );
    }

    /**
     * 分页查询公告数据
     *
     * @param page   分页对象<Notice>
     * @param status 状态
     * @return 公告分页数据对象
     */
    @Override
    public Page<Notice> pageByStatus(Page<Notice> page, Integer status) {
        // 调用分页方法进行分页数据的查询
        return page(page, new LambdaQueryWrapper<Notice>().eq(Notice::getStatus, status));
    }
}
